﻿package code {
	// class acts as a vertex that stores two points
	public class Vertex {
		public var x:Number;
		public var y:Number;
		
		public function Vertex(x:Number, y:Number) {
			this.x = x;
			this.y = y;
		}
		
				
		public static function cross(vertex1:Vertex, vertex2:Vertex):Vertex{
			return new Vertex(vertex1.y, -vertex1.x);
		}
		
		public static function dot(vertex1:Vertex, vertex2:Vertex):Number{
			return vertex1.x * vertex2.x + vertex1.y * vertex2.y;
		}
		
		public static function getAngle(vertex1:Vertex, vertex2:Vertex):Number{
			return Math.acos(Vertex.dot(vertex1, vertex2) / (Vertex.getMagnitude(vertex1) * Vertex.getMagnitude(vertex2)));
		}
		
		public static function getMagnitude(vertex1:Vertex):Number{
			return Math.sqrt(vertex1.x * vertex1.x + vertex1.y * vertex1.y);
		}
		
		public static function add(vertex1:Vertex, vertex2:Vertex){
			return new Vertex(vertex1.x + vertex2.x, vertex1.y + vertex2.y);
		}
		
		public static function subtract(vertex1:Vertex, vertex2:Vertex){
			return new Vertex(vertex2.x - vertex1.x, vertex2.y - vertex1.y);
		}
		
		public static function multiply(scalar:Number, vertex1:Vertex):Vertex{
			return new Vertex(vertex1.x * scalar, vertex1.y * scalar);
		}
		
		public static function divide(scalar:Number, vertex1:Vertex):Vertex{
			return Vertex.multiply(1 / scalar, vertex1);
		}
		
		// calculates displacement of two vertices using sqrt((y2 - y1) ^ 2 + (x2 - x2) ^ 2)
		public static function displace(p:Vertex, q:Vertex):Number{
			return Math.sqrt(Math.pow((q.y - p.y), 2) + Math.pow((q.x - p.x), 2));
		}

	}
	
}
